package wechat.custapp.corp.domain

import org.apache.log4j.Logger
import org.eclipse.xtend.lib.annotations.Accessors
import wechat.custapp.WCCorpCustApplication

class CustomerNotificationCorp {
	static Logger logger = Logger::getLogger("CustomerNotificationCorp")
	private static String CALLBACK_SERVER_URL = "http://weixin.shrct.com:8090"  //"http://210.22.183.30:8090"
	
	@Accessors WCCorpCustApplication app
	@Accessors String cbkurl
	
	def static CustomerNotificationCorp getIns(){
		new	CustomerNotificationCorp
	}
	
	def  String generateNotificationDetailsUrl(String id){
		cbkurl+'/notificationdetail?notificationId='+id
	}
	
	def void sendCustomerNotification(Iterable<String> users, String title, String body, String id){
		users.forEach[
			println('==========>send to '+ it)
		]
		if (users.size==0 || !users.exists[it!=null])  return;
		app.createNews()=>[
				withItem(title)=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url = generateNotificationDetailsUrl( id)
//					logger.info('url========>'+url)
				]
				withItem(body)=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= generateNotificationDetailsUrl(id)
				]
				send2Users(users)
			]
	}
}